<script setup lang="ts">
// #ifdef MP
import { onAddToFavorites, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
import { wxCollect, wxShare } from '@/libs/share'

onShareAppMessage(wxShare(true))
onShareTimeline(wxShare(false))
onAddToFavorites(wxCollect())
// #endif

import { onMounted, onUnmounted } from 'vue'

import { clear, isBottom, isUpdating, list, update } from './data'

onMounted(update)
onUnmounted(clear)
</script>

<template>
  <PageWrapper
    name="user-bill"
    :pageStyle="{ backgroundColor: '#FAFAFA' }"
  >
    <scroll-view
      class="bill"
      scroll-y
      :show-scrollbar="false"
      :lower-threshold="200"
      @scrolltolower="update"
    >
      <div
        v-for="(item, index) in list"
        :key="index"
        class="item"
      >
        <div class="title">{{ item.name }}</div>
        <div class="date">{{ item.createdTime }}</div>
        <div class="price">{{ item.changeAmountDesc }}</div>
        <div class="sum">{{ item.balanceDesc }}</div>
      </div>

      <div
        class="tip"
        @click="update"
      >{{ isBottom ? '—— 到底了 ——' : isUpdating ? '加载中' : '加载更多' }}</div>
    </scroll-view>
  </PageWrapper>
</template>

<style lang="less" scoped>
.bill {
  width: 100%;
  height: 100%;

  box-sizing: border-box;
  padding: 0 32rpx;

  touch-action: pan-y;

  .item {
    position: relative;
    width: 100%;
    height: 166rpx;

    margin-top: 16rpx;

    border-radius: 16rpx;
    background-color: #fff;
    box-shadow: 0 0 8rpx 0 rgba(#000, .08);

    font-size: 32rpx;
    line-height: 40rpx;

    .title {
      position: absolute;
      top: 34rpx;
      left: 32rpx;

      color: #222;
    }

    .price {
      position: absolute;
      top: 34rpx;
      right: 32rpx;

      color: #FF3700;
    }

    .date {
      position: absolute;
      bottom: 34rpx;
      left: 32rpx;

      color: #666;
      font-size: 28rpx;
    }

    .sum {
      position: absolute;
      bottom: 34rpx;
      right: 32rpx;

      color: #666;
      font-size: 28rpx;
    }
  }

  .tip {
    color: #666;
    font-size: 28rpx;
    line-height: 160rpx;
    text-align: center;
  }
}
</style>